package com.tang.controller;

import com.github.pagehelper.PageInfo;
import com.tang.pojo.Books;
import com.tang.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author Tom
 * @ClassName UpdateController
 * @Date 2021/10/29 15:57
 */
@Controller
@RequestMapping("/update")
public class UpdateController {
 @Autowired
 private BookService bookService;
 //跳转到书籍修改页面
 @RequestMapping("/toUpdateBook")
 public String toUpdateBook(int id, Model model){
  Books book = bookService.queryBookBookById(id);
  model.addAttribute("QueryBook",book);
  return "updateBook";
 }
 @RequestMapping("/updateBook")
 public String updateBook(Books books, HttpServletRequest request){
  bookService.updateBook(books);
  HttpSession session = request.getSession();
  PageInfo page = (PageInfo) session.getAttribute("page");
  int currentPage = page.getPageNum();
  return "redirect:/admin/queryAll?currentPage="+currentPage;
 }
}
    